const deleteImage = require("../../upload/controller/delete");
const comment = require("./delete_comment")
const db = require("../../models/index");
exports.create = async (obj) => {
  try {
    const data = {};
    data[`${obj.key}`] = obj.value;
    const article = await db.model_article_F.findAll({
      where: data,
      attributes: ["id", "image"],
    });
    if (article.length) {
      for (let index = 0; index < article.length; index++) {
        console.log("删除了文章：" + article[index].id);
        await deleteImage.create(article[index].image);
        await comment.create({
          key:"blog_id",
          value:article[index].id
        })
      }
      await db.model_article_F.destroy({
        where: data,
      });
      return true;
    }
    return false;
  } catch (error) {
    return error;
  }
};
